package co.gov.medellin.ssti.sub.service;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Collection;
import java.util.List;

import javax.naming.NamingException;

import co.gov.medellin.ssti.sub.common.ConexionFactory;
import co.gov.medellin.ssti.sub.model.dao.DAOFactory;
import co.gov.medellin.ssti.sub.model.dao.IRepDetBOTDAO;
import co.gov.medellin.ssti.sub.model.dao.exception.DAOException;
import co.gov.medellin.ssti.sub.model.vo.CondicionConsultaVO;
import co.gov.medellin.ssti.sub.model.vo.RepAtributoVO;
import co.gov.medellin.ssti.sub.model.vo.RepDetBOTVO;
import co.gov.medellin.ssti.sub.model.vo.ReporteDetVO;

public class RepDetBOTService {
	/**
	 * 
	 * @param atributosGenericos
	 * @param atributosEspecificos
	 * @param filtros
	 * @param criteria
	 * @return
	 * @throws DAOException
	 */
	public Collection<ReporteDetVO> findReporte(
			List<RepAtributoVO> atributosGenericos,
			List<RepAtributoVO> atributosEspecificos,
			List<CondicionConsultaVO> filtros, RepDetBOTVO criteria)
			throws DAOException {
		IRepDetBOTDAO repDetBOTDAO = null;
		try {
			Connection con = ConexionFactory.getInstance().getConnection();
			repDetBOTDAO = DAOFactory.getDAOFactory(DAOFactory.ORACLE)
					.getRepDetBOTDAO(con);
			return repDetBOTDAO.findReporte(atributosGenericos,
					atributosEspecificos, filtros, criteria);
		} catch (NamingException e) {
			throw new DAOException(e);
		} catch (SQLException e) {
			throw new DAOException(e);
		} finally {
			if (repDetBOTDAO != null) {
				if (!repDetBOTDAO.isConnClosed()) {
					repDetBOTDAO.close();
				}
			}
		}
	}

	/**
	 * 
	 * @param atributosGenericos
	 * @param atributosEspecificos
	 * @param filtros
	 * @param criteria
	 * @return
	 * @throws DAOException
	 */
	public Collection<ReporteDetVO> findReporteConGestor(
			List<RepAtributoVO> atributosGenericos,
			List<RepAtributoVO> atributosEspecificos,
			List<CondicionConsultaVO> filtros, RepDetBOTVO criteria)
			throws DAOException {
		IRepDetBOTDAO repDetBOTDAO = null;
		try {
			Connection con = ConexionFactory.getInstance().getConnection();
			repDetBOTDAO = DAOFactory.getDAOFactory(DAOFactory.ORACLE)
					.getRepDetBOTDAO(con);
			return repDetBOTDAO.findReporteConGestor(atributosGenericos,
					atributosEspecificos, filtros, criteria);
		} catch (NamingException e) {
			throw new DAOException(e);
		} catch (SQLException e) {
			throw new DAOException(e);
		} finally {
			if (repDetBOTDAO != null) {
				if (!repDetBOTDAO.isConnClosed()) {
					repDetBOTDAO.close();
				}
			}
		}
	}

	/**
	 * 
	 * @param filtros
	 * @param criteria
	 * @return
	 * @throws DAOException
	 */
	public Integer findCantidadBeneficiarios(List<CondicionConsultaVO> filtros,
			RepDetBOTVO criteria) throws DAOException {
		IRepDetBOTDAO repDetBOTDAO = null;
		try {
			Connection con = ConexionFactory.getInstance().getConnection();
			repDetBOTDAO = DAOFactory.getDAOFactory(DAOFactory.ORACLE)
					.getRepDetBOTDAO(con);
			return repDetBOTDAO.findCantidadBeneficiarios(filtros, criteria);
		} catch (NamingException e) {
			throw new DAOException(e);
		} catch (SQLException e) {
			throw new DAOException(e);
		} finally {
			if (repDetBOTDAO != null) {
				if (!repDetBOTDAO.isConnClosed()) {
					repDetBOTDAO.close();
				}
			}
		}
	}

	/**
	 * 
	 * @param filtros
	 * @param criteria
	 * @return
	 * @throws DAOException
	 */
	public Long findValorTotal(List<CondicionConsultaVO> filtros,
			RepDetBOTVO criteria) throws DAOException {
		IRepDetBOTDAO repDetBOTDAO = null;
		try {
			Connection con = ConexionFactory.getInstance().getConnection();
			repDetBOTDAO = DAOFactory.getDAOFactory(DAOFactory.ORACLE)
					.getRepDetBOTDAO(con);
			return repDetBOTDAO.findValorTotal(filtros, criteria);
		} catch (NamingException e) {
			throw new DAOException(e);
		} catch (SQLException e) {
			throw new DAOException(e);
		} finally {
			if (repDetBOTDAO != null) {
				if (!repDetBOTDAO.isConnClosed()) {
					repDetBOTDAO.close();
				}
			}
		}
	}

	/**
	 * 
	 * @param criteria
	 * @return
	 * @throws DAOException
	 */
	public RepDetBOTVO findFilters(RepDetBOTVO criteria) throws DAOException {
		IRepDetBOTDAO repDetBOTDAO = null;
		try {
			Connection con = ConexionFactory.getInstance().getConnection();
			repDetBOTDAO = DAOFactory.getDAOFactory(DAOFactory.ORACLE)
					.getRepDetBOTDAO(con);
			return repDetBOTDAO.findFilters(criteria);
		} catch (NamingException e) {
			throw new DAOException(e);
		} catch (SQLException e) {
			throw new DAOException(e);
		} finally {
			if (repDetBOTDAO != null) {
				if (!repDetBOTDAO.isConnClosed()) {
					repDetBOTDAO.close();
				}
			}
		}
	}
}
